<template>
  <!-- 安全验收计划 -->
  <base-breadcrumb>
    <searchData
      :search-data="searchOptions"
      @search="handleSearch"
    />

    <div class="page-body">
      <a-card :bordered="false">
        <title-name title="安全人员" />
        <div class="table-operateors mb20">
          <!-- <a-button type="primary" @click="handleUpdate('add')" v-btnPermission="'hse_019_add_01'"
                        >新增
                    </a-button> -->
        </div>
        <s-table
          ref="table"
          size="default"
          row-key="key"
          :columns="columns"
          :data="loadData"
          :alert="true"
          show-size-changer
          show-quick-jumper
          show-pagination="auto"
        >
          <span
            slot="sort"
            slot-scope="text, record, index"
          >{{ index + 1 }}</span>
          <template
            slot="operator"
            slot-scope="text, record"
          >
            <template>
              <a
                v-btnPermission="'hse_015_loo_02'"
                class="base-btn"
                @click="handleUpdate('look', record)"
              >查看</a>
              <!-- <a-divider
                                v-if="record.auditStatus === 'DRAFT'"
                                type="vertical"
                                v-btnPermission="'hse_019_loo_04'"
                            />
                            <a
                                v-if="record.auditStatus === 'DRAFT'"
                                class="base-btn"
                                @click="handleUpdate('edit', record)"
                                v-btnPermission="'hse_019_edi_02'"
                                >编辑</a
                            >
                            <a-divider
                                v-if="record.auditStatus == 'DRAFT'"
                                type="vertical"
                                v-btnPermission="'hse_019_edi_02'"
                            />
                            <a
                                class="base-btn"
                                v-if="record.auditStatus == 'DRAFT'"
                                @click="handleUpdate('del', record)"
                                v-btnPermission="'hse_019_del_03'"
                                >删除</a
                            > -->
            </template>
          </template>

          <template
            slot="auditStatus"
            slot-scope="text, record"
          >
            <list-status
              :status="record.auditStatus"
              conversion="en"
              :text="text"
            />
          </template>
        </s-table>
      </a-card>
    </div>
  </base-breadcrumb>
</template>

<script>
import { STable } from '@/components'
import { getSecurityPersonnelList, deleteSecurityPersonnel } from '@/api/safetySupervision/securityPersonnel'
import SelectSubCompany from '@/components/Select/SelectSubCompany' // 分公司
import SelectProject from '@/components/Select/SelectProject' // 项目
import OrgTreeSelect from '@/components/OrgTreeSelect'
import { employees } from '@/api/quality/safe' // api
import SelectSubcontractor from '@/components/Select/SelectSubcontractor' // 项目
import Vue from 'vue'
const searchOptions = [
    // {
    //     name: '所属分公司',
    //     valueKey: 'branchComId',
    //     type: SelectSubCompany,
    // },
    {
          name: '所属单位',
          valueKey: 'searchQuery',
          type: OrgTreeSelect,
        },
    // {
    //     name: '所属项目',
    //     keyValue: 'branchComId',
    //     valueKey: 'projectId',
    //     type: SelectProject,
    // },
    {
        name: '所属分包',
        keyValue: 'projectId',
        valueKey: 'subContractorId',
        type: SelectSubcontractor,
    },
    {
        name: '姓名',
        value: 'name',
        type: 'input',
    },

    {
        name: '状态',
        value: 'auditStatus',
        type: 'select',
        data: [
            {
                value: '0',
                label: '未提交',
            },
            {
                value: '1',
                label: '已提交',
            },
        ],
    },
]
const columns = [
    {
        title: '序号',
        dataIndex: 'sort',
        scopedSlots: { customRender: 'sort' },
    },
    {
        title: '姓名',
        dataIndex: 'userName',
    },
    {
        title: '类型',
        dataIndex: 'level',
    },
    {
        title: '岗位信息',
        dataIndex: 'jobInformation',
    },
    {
        title: '性别',
        dataIndex: 'gender',
    },
    {
        title: '职称',
        dataIndex: 'jobTitleName',
    },
    {
        title: '学历',
        dataIndex: 'degree',
    },
    {
        title: '专业',
        dataIndex: 'education',
    },
    {
        title: '联系电话',
        dataIndex: 'phone',
    },

    {
        title: '状态',
        dataIndex: 'auditStatus',
        scopedSlots: { customRender: 'auditStatus' },
    },
    {
        title: ' 操作',
        dataIndex: 'operator',
        scopedSlots: { customRender: 'operator' },
    },
]
export default {
    name:'a'+Date.now(),
    components: {
        ThemeChoose,
        STable,
    },
    data() {
        this.searchOptions = searchOptions
        this.columns = columns
        return {
            queryParam: {
                safetyInstructor:true
            },
            loadData: async (parameter) => {
                const requestParameters = Object.assign({}, parameter, this.queryParam)
                const [err, res] = await getSecurityPersonnelList(requestParameters)
                return new Promise((resolve, reject) => {
                    if (err) {
                        reject(err)
                    } else {
                        resolve(res)
                    }
                })
            },
        }
    },
    methods: {
        handleSearch(val = {}) {
            this.queryParam = {
                ...val,
                safetyInstructor:true
            }

            this.$refs.table.refresh(true)
        },
        async deleteSecurityPersonnel(data) {
            const [err, res] = await deleteSecurityPersonnel({ id: data.id })
            if (!err) {
                this.$message.success('成功')
                this.$refs.table.refresh(true)
            }
        },
        // 处理更新操作（新增、编辑）
        async handleUpdate(type, data = {}) {
            if (type == 'del') {
                let that = this
                this.$confirm({
                    title: '温馨提示',
                    content: '确定是否删除数据？',
                    okText: '确认',
                    okType: 'danger',
                    cancelText: '取消',
                    onOk: () => {
                        return that.deleteSecurityPersonnel(data)
                    },
                })
            } else {
                this.$router.push({
                    name: 'updateSecurityPersonnel',
                    query: {
                        id: data.id || '',
                        pageType: type,
                    },
                })
            }
        },
    },
}
</script>
